﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            //            1、学生类：学号、姓名、年龄
            //2、请选择：1、添加学生信息。2、查询学生信息，3、删除学生信息  4、退出
            //3、重复的学号不能添加。
            //4、查询学生信息功能中有：1、查询所有（按学号排序）2、按学号查询（查没有，则打印查无此学生）
            ArrayList list = new ArrayList();
            Hashtable ht = new Hashtable();//以键值对的形式存储数据。无序，且key不能重复的。
            Student s1 = new Student(1, "张三", 18);
            Student s2 = new Student(2, "李四", 20);
            Student s3 = new Student(3, "王五", 19);
            Student s4 = new Student(4, "赵六", 21);
            ht.Add(s1.num, s1);
            ht.Add(s2.num, s2);
            ht.Add(s3.num, s3);
            ht.Add(s4.num, s4);
            Console.WriteLine("请选择1、添加学生信息  2、查询学生信息  3、删除学生信息  4、退出");
            int key = int.Parse(Console.ReadLine());

            switch (key)
            {
                case 1:
                    test1();

                    break;


                case 2:
                    Console.WriteLine("查询学生信息：1、查询所有（按学号排序）2、按学号查询");
                    int bb = int.Parse(Console.ReadLine());
                    if (bb == 1)
                    {
                       
                        foreach (Student a in list)
                        {
                            Console.WriteLine(a);
                        }
                    }
                    else if (bb == 2)
                    {
                        Console.Write("请输入你的学号：");
                        int Id = int.Parse(Console.ReadLine());
                        if (ht.Contains(Id))
                        {
                            Console.WriteLine(ht[Id]);
                        }
                        else
                        {
                            Console.WriteLine("查无此学生!!!");
                        }
                    }

                    break;


                case 3:
                    list.Remove(s1);
                    list.Remove(s2);
                    list.Remove(s3);
                    list.Remove(s4);
                    Console.WriteLine("======删除后======");
                    foreach (var item in list)
                    {
                        Console.WriteLine(list);
                    }
                    break;


                case 4:
                    Console.WriteLine("退出");

                    break;



                default:
                    break;
            }

          
    }
        private static void test11()
        {
            
        }
      

        private static void test3()
        {
            ArrayList list = new ArrayList();
            Student s1 = new Student(1, "猪八戒", 20);
            Student s2 = new Student(2, "海绵宝宝", 21);
            Student s3 = new Student(3, "喜羊羊", 22);
            Student s4 = new Student(4, "萧炎", 23);
            list.Add(s1);
            list.Add(s2);
            list.Add(s3);
            list.Add(s4);
         
           

        }

        private static void test2()
        {
            ArrayList list = new ArrayList();
            Student s1 = new Student(1, "猪八戒", 20);
            Student s2 = new Student(2, "海绵宝宝", 21);
            Student s3 = new Student(3, "喜羊羊", 22);
            Student s4 = new Student(4, "萧炎", 23);
            list.Add(s1);
            list.Add(s2);
            list.Add(s3);
            list.Add(s4);
            Console.WriteLine(list.Contains(s1));
            Console.WriteLine(list.Contains(s2));
            Console.WriteLine(list.Contains(s3));
            Console.WriteLine(list.Contains(s4));

        }

        static void test1()
        {
            ArrayList list = new ArrayList();
            Console.WriteLine("请输入学生信息姓名");
            string a = Console.ReadLine();
            Console.WriteLine("请输入学生信息学号");
           int b = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入学生信息年纪");
            int c = int.Parse(Console.ReadLine());

            Student s1 = new Student();
            Student s2 = new Student();
            Student s3 = new Student();
          
            s1.name = a;
            s1.num = b;
            s1.age = c;
            s2.name = a;
            s2.num = b;
            s2.age = c;
            s3.name = a;
            s3.num = b;
            s3.age = c;

            list.Add(s1);
            list.Add(s2);
            list.Add(s3);
            Console.WriteLine("插入成功");
         
        }
        }
    }

